{
  "name": "Telecom Customer Service & Complaint Resolution Agent",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "7fd8b791-4095-4d99-abc5-7858d1d31be6",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -224,
        -80
      ],
      "webhookId": "e69fd63a-4cf6-443e-ac3e-4d7bcb04f5d2",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "customer_message",
              "value": "={{ $json.message.text }}",
              "type": "string"
            },
            {
              "id": "id-2",
              "name": "customer_name",
              "value": "={{ $json.message.from.first_name + ' ' + ($json.message.from.last_name || '') }}",
              "type": "string"
            },
            {
              "id": "id-3",
              "name": "chat_id",
              "value": "={{ $json.message.chat.id }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "8fbc8264-aacc-4dca-a42e-87e94a6b73e7",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        48,
        -80
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Customer Name: {{ $json.customer_name }}\nCustomer Message: {{ $json.customer_message }}\nChat ID: {{ $json.chat_id }}",
        "options": {
          "systemMessage": "=You are a Telecom Customer Service and Complaint Resolution Assistant.\n\nYour responsibilities:\n1. Identify whether the customer wants to REGISTER a new complaint or CHECK complaint status.\n\n2. For new complaints, collect the following information:\n   - Account Number\n   - Date of Issue\n   - Type of Issue (e.g., Network Outage, Billing Error, Poor Signal, Service Disruption, etc.)\n   - Brief description\n   \n   Do NOT ask for email address - it will be automatically retrieved from the Customer Account Master.\n\n3. Validate the account using the Customer Account Master Tool and extract:\n   - Customer_Name\n   - Email (this will be used for sending the acknowledgement email)\n   - Account_Status (to verify if the account is Active or Inactive)\n\n4. If the account is Active:\n   - Generate a unique complaint reference ID in format: COMP-YYYYMMDD-[last 4 digits of account]-HHmmss\n   - Register the complaint using the Complaint Register Tool with all collected information\n   - Send email confirmation using the Gmail Tool with the Email retrieved from Customer Account Master Tool\n   - Clearly explain the next steps and expected resolution timelines to the customer\n   - Respond to the customer using Telegram Response Tool\n\n5. If the account is Inactive or invalid:\n   - Politely explain the reason why the complaint cannot be registered\n   - Do NOT register the complaint\n   - Respond to the customer using Telegram Response Tool\n\n6. For status checks:\n   - Ask for complaint reference ID if the customer hasn't provided it\n   - Retrieve the current status using the Complaint Status Tool\n   - Explain the current resolution stage in simple, customer-friendly language\n   - Provide the expected timeline for the next update or resolution\n   - Respond to the customer using Telegram Response Tool\n\nStrict rules:\n- Do NOT make technical commitments or promises about fixes.\n- Do NOT guarantee specific service restoration times.\n- Be clear, calm, and professional in all communications.\n- Maintain a polite and empathetic tone - remember that service disruptions cause frustration for customers.\n- Avoid technical jargon - use simple business language.\n- ALWAYS use the Telegram Response Tool to send your final response to the customer.\n- The customer's email is already stored in the system - retrieve it from Customer Account Master Tool, do NOT ask the customer for it."
        }
      },
      "id": "4b9135d7-3fb3-4b54-ad3d-ebe35b503570",
      "name": "Telecom Customer Service Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        272,
        -80
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o"
        },
        "builtInTools": {},
        "options": {
          "temperature": 0.2
        }
      },
      "id": "68a25f8b-e222-4c3c-83a2-531c8e9b395d",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        96,
        144
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Workflow Configuration').item.json.chat_id }}",
        "contextWindowLength": 10
      },
      "id": "775b94ad-9558-45be-95a3-700c51fd0b9d",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        256,
        144
      ]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to validate customer account information. Provide the account number to check if the account exists, is active, and retrieve plan type and service details. Returns account_status, plan_type, and service_end_date.",
        "documentId": {
          "__rl": true,
          "value": "1KjQuLJeeb85r2h7JxnWbdP4qejb5-u1rTmYiRh1MzpY",
          "mode": "list",
          "cachedResultName": "Customer_Account_Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1KjQuLJeeb85r2h7JxnWbdP4qejb5-u1rTmYiRh1MzpY/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1KjQuLJeeb85r2h7JxnWbdP4qejb5-u1rTmYiRh1MzpY/edit#gid=0"
        },
        "options": {}
      },
      "id": "749ef416-c255-401b-8ca5-c2f558c74acb",
      "name": "Customer Account Master Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        400,
        144
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "=Use this tool to register a new complaint. Provide complaint_reference_id, account_number, issue_date, complaint_type, description, and complaint_status (set to Registered). This creates an official complaint record.",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1vvvb6O71zbLP_Ol_43cYcFcMHUuOzlcVnra9hYhpeKY",
          "mode": "list",
          "cachedResultName": "Complaint_Register",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1vvvb6O71zbLP_Ol_43cYcFcMHUuOzlcVnra9hYhpeKY/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1vvvb6O71zbLP_Ol_43cYcFcMHUuOzlcVnra9hYhpeKY/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Complaint_Ref_ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Complaint_Ref_ID', ``, 'string') }}",
            "Account_Number": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Account_Number', ``, 'string') }}",
            "Customer_Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Customer_Name', ``, 'string') }}",
            "Issue_Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Issue_Date', ``, 'string') }}",
            "Complaint_Type": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Complaint_Type', ``, 'string') }}",
            "Description": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Description', ``, 'string') }}",
            "Complaint_Status": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Complaint_Status', ``, 'string') }}",
            "Created_At": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Created_At', ``, 'string') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Complaint_Ref_ID",
              "displayName": "Complaint_Ref_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Account_Number",
              "displayName": "Account_Number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer_Name",
              "displayName": "Customer_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Issue_Date",
              "displayName": "Issue_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Complaint_Type",
              "displayName": "Complaint_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Description",
              "displayName": "Description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Complaint_Status",
              "displayName": "Complaint_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Created_At",
              "displayName": "Created_At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "b2e5b706-56c8-45c3-9b4c-bf62207fbd0d",
      "name": "Complaint Register Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        560,
        144
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to check the status of an existing complaint. Provide the complaint_reference_id to retrieve current resolution stage, last updated date, and status information.",
        "documentId": {
          "__rl": true,
          "value": "1ht_lDYYmTGWJJA580BvVl8dCxPPkwPRkUtEM1VI2L6U",
          "mode": "list",
          "cachedResultName": "Complaint_Status",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ht_lDYYmTGWJJA580BvVl8dCxPPkwPRkUtEM1VI2L6U/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ht_lDYYmTGWJJA580BvVl8dCxPPkwPRkUtEM1VI2L6U/edit#gid=0"
        },
        "options": {}
      },
      "id": "5245c507-0628-430a-b932-2875c2c07bc6",
      "name": "Complaint Status Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        704,
        144
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to send an official complaint acknowledgement email to the customer. Provide recipient email, complaint reference ID, account number, and issue details.",
        "sendTo": "={{ $fromAI('customer_email', 'Customer email address', 'string') }}",
        "subject": "={{ $fromAI('email_subject', 'Email subject line', 'string', 'Complaint Registration Confirmation') }}",
        "message": "={{ $fromAI('email_body', 'Email body content with complaint details', 'string') }}",
        "options": {}
      },
      "id": "2417509d-e671-4164-8851-59244840ddce",
      "name": "Gmail Tool",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        848,
        144
      ],
      "webhookId": "15cba1c5-81ac-4d4d-9a13-35fc51ad3bbe",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        704,
        -80
      ],
      "id": "123dd2c3-3c46-47e3-81ab-76ab5fc77de1",
      "name": "Send a text message",
      "webhookId": "3c111795-fe7d-497d-b853-a6432330a256",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Telecom Customer Service Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Telecom Customer Service Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Telecom Customer Service Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Customer Account Master Tool": {
      "ai_tool": [
        [
          {
            "node": "Telecom Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Complaint Register Tool": {
      "ai_tool": [
        [
          {
            "node": "Telecom Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Complaint Status Tool": {
      "ai_tool": [
        [
          {
            "node": "Telecom Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Tool": {
      "ai_tool": [
        [
          {
            "node": "Telecom Customer Service Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Telecom Customer Service Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6a6380ee-b65d-467a-afbc-b0fd60d7db4c",
  "meta": {
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "I9S0MH61TMcjGVXK",
  "tags": []
}